package com.qf.fmall01.service.impl;

import com.qf.fmall01.dao.IndexImgMapper;
import com.qf.fmall01.entity.IndexImg;
import com.qf.fmall01.service.IndexImgService;
import com.qf.fmall01.vo.ResStatus;
import com.qf.fmall01.vo.ResultVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import tk.mybatis.mapper.entity.Example;

import java.util.List;

@Service
public class IndexImgServiceImpl implements IndexImgService {

    @SuppressWarnings("SpringJavaInjectionPointsAutowiringInspection")
    @Autowired
    private IndexImgMapper indexImgMapper;

    @Transactional(propagation = Propagation.SUPPORTS)
    @Override
    public ResultVO listIndexImgs() {

        ResultVO vo = new ResultVO();

        Example example = new Example(IndexImg.class);

        Example.Criteria criteria = example.createCriteria();

        criteria.andEqualTo("status","1");

        example.setOrderByClause("seq");   // order by seq

        List<IndexImg> indexImgs = indexImgMapper.selectByExample(example);

        if (indexImgs .size() == 0){
            vo.setCode(ResStatus.NO);
            vo.setMsg("没有查询到轮播图信息");
        }else {
            vo.setCode(ResStatus.OK);
            vo.setMsg("success");
            vo.setData(indexImgs);
        }

        return vo;
    }
}
